import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:baidu_face/baidu_face.dart';
import 'package:permission_handler/permission_handler.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _baiduFacePlugin = BaiduFace();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    _baiduFacePlugin.init('tUC9VXycq4gbsyNMvu34D51q', 'IisOqYvGkHfbjZccrUiwf294BB5oMnVO');
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: [
            ElevatedButton(
                onPressed: () async {
                  // 申请权限
                  PermissionStatus permissions = await Permission.camera.request();
                  if (permissions != PermissionStatus.granted) {

                    return;
                  }

                  Map map = await _baiduFacePlugin.liveDetect();
                  print("arg: $map");
                },
                child: const Text("liveDetect"))
          ],
        ),
      ),
    );
  }
}
